package com.hsxc.cdz.monitor.bean.extend.pile.message;

import com.hsxc.cdz.base.bean.Bill;
import com.hsxc.cdz.base.util.TimeFormatter;
import com.hsxc.cdz.mgmt.GlobalManager;
import com.hsxc.cdz.monitor.FSM.CachePile;
import com.hsxc.cdz.monitor.bean.extend.Content;
import com.hsxc.cdz.monitor.bean.extend.pile.content.BillPileContent;

/**
 * 充电桩上传账单的报文
 * 
 * @author 刘力文
 *
 */
public class BillPileMsg extends PileMessage<BillPileContent> {

	/*****************************************************************/
	// 构造方法
	public BillPileMsg() {
	}

	public BillPileMsg(byte[] data) throws Exception {
		this();
		super.createMessage(data);
	}

	/*****************************************************************/
	// 重写父类方法
	@Override
	public boolean execute() {
		CachePile cachePile = GlobalManager.pileManager.getPile(this.getAddress());
		if (cachePile == null) {
			return false;
		}
		BillPileContent billContent = this.getContent();
		Bill bill = new Bill();
		bill.setUserNO(billContent.getCardNum());
		bill.setPileNO(this.getAddress());
		bill.setGenerateTime(TimeFormatter.toTimeYear());
		bill.setStartTime(billContent.getStartTime());
		bill.setStopTime(billContent.getEndTime());
		bill.setChargeFee(((double) billContent.getSumMoney()) / Content.MULTIOLE);
		bill.setServiceFee(((double) billContent.getServiceMon()) / Content.MULTIOLE);
		bill.setFeeSum(bill.getChargeFee() + bill.getServiceFee());
		bill.setState(billContent.getIsPay());
		bill.setPayTime(TimeFormatter.toTimeYear());
		bill.setDegreeBefore(((double) billContent.getStartRecord()) / Content.MULTIOLE);
		bill.setDegreeAfter(((double) billContent.getEndRecord()) / Content.MULTIOLE);
		bill.setChargeDegree(((double) billContent.getElectricity()) / Content.MULTIOLE);
		bill.setBalanceIcBefore(((double) billContent.getStartCardMon()) / Content.MULTIOLE);
		bill.setBalanceIcAfter(((double) billContent.getEndCardMon()) / Content.MULTIOLE);

		// GlobalManager.billManager.storeBill(bill);
		return true;

	}

	public void setContent(byte[] data) throws Exception {
		super.setContent(new BillPileContent(data));
	}
}
